package com.rongxun.hbwallet.mvp.presenter;

import android.content.Context;
import android.support.annotation.NonNull;

import com.rongxun.base.BaseObserver;
import com.rongxun.base.BasePresenter;
import com.rongxun.base.ResponseSubscriber;
import com.rongxun.hbwallet.model.Response;
import com.rongxun.hbwallet.model.bean.Notice;
import com.rongxun.hbwallet.model.bean.SweetsInfo;
import com.rongxun.hbwallet.model.bean.User;
import com.rongxun.hbwallet.model.bean.UserCandyInfo;
import com.rongxun.hbwallet.model.bean.UserCitymoneyInfo;
import com.rongxun.hbwallet.model.entity.SubCate;
import com.rongxun.hbwallet.mvp.contract.IMySelf;
import com.rongxun.utils.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.internal.observers.BasicFuseableObserver;

/**
 * 创建者     庄丰泽
 * 创建时间   2018/5/18 13:42
 * 描述   首页
 */

public class MySelfPresenter extends BasePresenter<IMySelf.IView, IMySelf.IModel> implements IMySelf.IPresenter {
    public MySelfPresenter(@NonNull IMySelf.IView pUi, @NonNull IMySelf.IModel pModel) {
        super(pUi, pModel);
    }

    @Override
    public void setSelection(String[] titles) {
        List<SubCate> mlist = new ArrayList<>();
        SubCate header = new SubCate();
        header.setItemType(0);
        mlist.add(header);
        for (int i = 0; i < titles.length; i++) {
            SubCate s = new SubCate();
            s.setTitle(titles[i]);
            s.setItemType(1);
            mlist.add(s);
        }
        SubCate bottom = new SubCate();
        bottom.setItemType(2);
        mlist.add(bottom);
        getView().showSelection(mlist);
    }

    @Override
    public void getUserCityMoneyInfo() {
        addSubscribe(getModel()
                .getUserCityMoneyInfo()
                .subscribeWith(new ResponseSubscriber<UserCitymoneyInfo>(getView()) {
                    @Override
                    public void onSuccess(UserCitymoneyInfo info) {
                        getView().getUserCityMoneyInfo(info);
                    }
                    @Override
                    public void disposeEorCode(String message, String code) {

                    }
                }));
    }

    @Override
    public void getConfig(Boolean is_into, String key_value) {
        addSubscribe(getModel().getConfig(key_value).subscribeWith(new BaseObserver<String>(getView()) {
            @Override
            public void onSuccess(String s, Context context) {
                if (!is_into) {
                    getView().getExchangeRatio(s);
                } else {
                    getView().IntoExchangeToken(s);
                }
            }
        }));
    }

    @Override
    public void getUserCandyInfo() {
        addSubscribe(getModel()
                .getUserCandyInfo()
                .subscribeWith(new ResponseSubscriber<UserCandyInfo>(getView()) {
                    @Override
                    public void onSuccess(UserCandyInfo info) {
                        getView().showUserCandyInfo(info);
                    }

                    @Override
                    public void disposeEorCode(String message, String code) {

                    }
                }));
    }

}
